home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Applications / chipmunk-basic-304 / basic.man next >
Encoding:
Text File  |  1994-10-01  |  18.5 KB  |  741 lines  |  [TEXT/ttxt]

  1.     BASIC(1)        chipmunk-basic v3.0             BASIC(1)
  2.  
  3.  
  4.     Chipmunk BASIC - 'BASIC' language interpreter
  5.     
  6.  
  7.     SYNOPSIS    ( UNIX )
  8.  
  9.     basic [ filename ]
  10.  
  11.     DESCRIPTION
  12.  
  13.     Chipmunk basic is an interpreter for the BASIC language. If a
  14.     filename parameter is given, then the named program file is
  15.     loaded and run as a Basic program.  
  16.  
  17.     Basic commands and statements can be entered and interpreted in
  18.     immediate mode or executed as program statements when the Basic
  19.     program is run.  A built-in line number based editor allows
  20.     program input from the console keyboard.  See below for the
  21.     commands the interpreter recognizes.
  22.     
  23.     FLAGS
  24.  
  25.     none
  26.  
  27.     COMMANDS
  28.         
  29.     Standard mumbleSoft Basic Commands:
  30.  
  31.     load STRINGEXPR
  32.  
  33.         Load a program into memory from the named file. The
  34.         program previously in memory is erased.  All
  35.         variables are cleared.  All lines in the file must
  36.         begin with a line number.  Line numbers do not
  37.         need to be in increasing order.
  38.  
  39.  
  40.     save STRINGEXPR
  41.  
  42.         Save the current program to a named file.
  43.  
  44.     new
  45.  
  46.         Erase the program in memory.  All files are closed and
  47.         all variables are cleared.
  48.  
  49.     clear
  50.  
  51.         All  variables are cleared.  All arrays and string
  52.         variables are deallocated.
  53.  
  54.     run { LINENUM }
  55.     run { STRINGEXPR { , LINENUM } }
  56.  
  57.         Begin execution of the program at the first line, or at
  58.         the specified line.  All variables are cleared.  If a
  59.         STRINGEXPR is given then the BASIC program with that name
  60.         file is loaded into memory first.  Program lines are
  61.         executed in line number order.
  62.  
  63.     cont
  64.  
  65.         CONTinue execution of the program on the next statement
  66.         after the statement on which the program stopped execution
  67.         due to a STOP command or an error.
  68.  
  69.     goto LINENUM
  70.  
  71.         This statement will transfer control to the line number
  72.         specified.  If the program is not running, then this
  73.         command will begin execution at the specified line
  74.         without clearing the variables.  An "Undefined line"
  75.         error will occur if LINENUM doesn't exist in the program.
  76.  
  77.     list
  78.         List the whole program.
  79.  
  80.     list 1-3
  81.         List lines 1 to 2
  82.  
  83.     list -2
  84.         List lines up to 1
  85.  
  86.     list 1
  87.         List line 1
  88.     
  89.     list 2-
  90.         List lines from 2 on
  91.  
  92.     merge STRINGEXPR
  93.  
  94.         Load a program into memory.  The previous program
  95.         remains in memory; if a line exists in both programs,
  96.         the newly loaded line is kept.
  97.  
  98.     renum STRINGEXPR VAL { , VAL { , VAL { , VAL} } }
  99.  
  100.         Renumber program lines.  By default, the new sequence
  101.         is 10,20,30,... The first argument is a new initial
  102.         line number; the second argument is the increment
  103.         between line numbers. The third and fourth arguments,
  104.         if present, specify a limiting range of old line numbers
  105.         to renumber.  RENUM can be used to move non-overlapping
  106.         blocks of code.
  107.      
  108.     edit LINENUM
  109.  
  110.         Edit a given line. If the exit from the edit is via a
  111.         cntrl-c then do not change the line.
  112.             i    insert till <return>
  113.             x    delete one char
  114.             A    append to end of line
  115.  
  116.     delete LINENUM - LINENUM
  117.  
  118.         Delete a specified range of lines. If not found then no
  119.         lines will be deleted.  If used inside a program, DEL
  120.         will terminate execution only if it deletes the line on
  121.         which it appears.
  122.  
  123.     exit
  124.     bye
  125.     quit
  126.  
  127.         Terminates the basic interpreter, ending program
  128.         execution and closing all files.
  129.  
  130.  
  131.     STATEMENTS
  132.  
  133.     { let } VAR = EXPR
  134.  
  135.         Assign a value to a variable.  Variable names can be up
  136.         to 31 significant characters, consisting of letters,
  137.         digits, underscores, and an ending dollar sign. 
  138.         Variable names are case-insensitive.  Variables can
  139.         hold real numbers (IEEE double) or strings of up
  140.         to 254 characters.  If the variable name ends with a
  141.         "$" it holds strings, otherwise it holds numbers.  If a
  142.         statement starts with a variable name then an implied
  143.         LET is assumed.
  144.  
  145.     print or '?' VAL | STRINGVAL { { , | ; } VAL ... } { ; }
  146.     print #FNUM, VAL ...
  147.  
  148.         This command will print its parameters. If a
  149.         semi-colon is used between parameters then no spaces
  150.         are inserted between those parameters.  The print
  151.         output is terminated with a carriage return unless the
  152.         parameter list ends with a semi-colon.  If a file
  153.         descriptor is given then output is redirected to the
  154.         given file.
  155.  
  156.         If a
  157.             tab(VAL)
  158.         is found in a print statement, then print output will
  159.         skip to the horizontal position specified by VAL.
  160.  
  161.     input { # FNUM , } { VAR | STRINGVAR } { , VAR ... }
  162.  
  163.     input "prompt"; { VAR | STRINGVAR }
  164.  
  165.         Input from a terminal or from a file. If the input is
  166.         from the terminal then a prompt message can also be
  167.         added.
  168.  
  169.     get STRINGVAR
  170.     
  171.         Gets one character from the console keyboard.  Blocking.
  172.     
  173.     cls
  174.         Clear the terminals screen.  Leaves the cursor in the
  175.         upper left corner.  For Applesoft BASIC fans, the "home"
  176.         command will also do this.
  177.  
  178.     end
  179.  
  180.         Terminates program execution and returns to the command
  181.         prompt.  Not required.
  182.  
  183.     stop
  184.  
  185.         Stops the execution of the program and returns to
  186.         the command prompt.  Prints a "Break..." message.
  187.  
  188.     if EXPR then STATEMENT { : STATEMENT } { : else STATEMENT }
  189.     if EXPR then LINENUM
  190.  
  191.         The IF statement.  If the condition is true then the
  192.         STATEMENTS after the THEN are executed and the
  193.         statements after the ELSE are skipped.  If the
  194.         condition is false then the statements after the "else"
  195.         are executed instead.  If the item after "then" is a
  196.         line number then a goto is executed.
  197.  
  198.     for VAR = EXPR to EXPR { step EXPR }
  199.  
  200.         Beginning of a "for next" loop.  It takes a starting
  201.         value, a limit and an optional step argument.  If the
  202.         step value is negative, the variable counts down.  The
  203.         body of the loop is not executed if the end condition
  204.         is true initially.
  205.  
  206.         Example:
  207.             for i=1 to 10 : print i, : next i
  208.             rem prints the numbers from 1 through 10
  209.  
  210.     next { VAR }
  211.  
  212.         End of a "for next" loop.  If the termination
  213.         conditions are met then execution falls through to the
  214.         following statement, otherwise execution returns to the
  215.         statement following the corresponding "for" statement.
  216.         The "next" does not need a variable name parameter.  If
  217.         this is the case the innermost "for" loop is used.
  218.  
  219.     while { EXPR }
  220.  
  221.         Start of a WHILE loop. The loop is repeated until EXPR
  222.         is false. If EXPR is false at loop entry, then the loop
  223.         is not executed at all. A WHILE loop must be
  224.         terminated by a WEND statement.
  225.  
  226.     wend { EXPR }
  227.  
  228.         Terminating statement of a WHILE loop.  If EXPR is true
  229.         then exit the loop.  Only one WEND is allowed for each
  230.         WHILE.  A WHILE-WEND loop without a condition will loop
  231.         forever.  A WHILE (condition) ... WEND (1) construct can
  232.         be used as a multiline IF-ENDIF construct.
  233.  
  234.     gosub LINENUM
  235.  
  236.         Transfer command to a line number. Save return address
  237.         so that the program can resume execution at the
  238.         statement after the "gosub" command.  The recursion
  239.         depth is limited only by available memory.
  240.  
  241.     return
  242.  
  243.         Returns from the most recently activated subroutine
  244.         call (must have been called by gosub).
  245.  
  246.     on EXPR   goto  LINENUM { , LINENUM ... }
  247.     on EXPR   gosub LINENUM { , LINENUM ... }
  248.     on error goto  LINENUM
  249.  
  250.         This command will execute either a goto or a gosub to
  251.         the specified line number indexed by the value of EXPR.
  252.         
  253.         If the error form is used, only one linenumber is
  254.         allowed.  LINENUM is the line to which control is
  255.         transferred if an error occurs.  A GOTO statement can
  256.         be used to resume execution.
  257.  
  258.     sub NAME ( VAR { , VAR ... } }
  259.  
  260.         Subroutine entry.  May be called by a GOSUB statement or
  261.         by NAME. The variables in the VAR list become local
  262.         variables. Use the RETURN statement to exit the subroutine.
  263.         
  264.         Example:
  265.             110  gosub 2000 (7, j) : rem Pass 7 and j by value.
  266.             120  foo (7, b+1)      : rem Can also call by name.
  267.             ...
  268.             2000 sub foo (x,y,z) : rem z is a local variable
  269.             2010   print x       : prints 7 the first time
  270.             2090 return         : rem restores x,y,z
  271.  
  272.     dim VAR( d { , d { , d } } ) { , VAR( d { , d { , d } } ) }
  273.  
  274.         Dimension an array or list of arrays (string or numeric). 
  275.         A maximum of 4 dimensions can be used. The maximum
  276.         dimension size is limited by available memory. Legal
  277.         array subscripts are from 0 up and including the
  278.         dimension specified; d+1 elements are allocated.  All
  279.         arrays must be dimensioned before use and can be
  280.         dimensioned only once in a program.
  281.         
  282.         Example:
  283.             10 dim a(10)
  284.             20 for i=0 to 10
  285.             30   a(i) = i^2
  286.             40 next i
  287.             50 print a(5) : rem should print 25
  288.  
  289.     read VAR { , VAR }
  290.  
  291.         Read data from the DATA statements contained in the
  292.         program. List items can be either string or numeric
  293.         variables. Reading past the end the last DATA statement
  294.         generates an error.
  295.  
  296.     data ITEM { , ITEM }
  297.  
  298.         DATA statements contain the data used in the READ
  299.         statements. Items must be separated by commas.  The
  300.         items may be either numeric or string expressions,
  301.         corresponding to the type of variable being read.
  302.         Reading the wrong kind of object produces a "Type
  303.         mismatch" error.
  304.  
  305.     restore { LINENUM }
  306.  
  307.         The RESTORE statement causes the next READ to use the
  308.         first DATA statement in the program.  If a LINENUM is
  309.         given then the DATA statement on or after that
  310.         particular line is used next.
  311.  
  312.     rem or "`"
  313.  
  314.         A remark or comment statement.  Ignored by the program
  315.         during execution, however a REM statement can be the
  316.         target of a GOTO or GOSUB.
  317.  
  318.     open STRINGEXPR for { input|output|append } as # FNUM
  319.  
  320.         Open a file. The { input|output|append } parameter
  321.         specifies whether the file is to be read, written or
  322.         appended.  If STRINGEXPR is "stdin" for input or
  323.         "stdout" for output then the console will be used
  324.         instead of a file.  A "file not found" error will
  325.         occur if a non-existant file is specified in an OPEN
  326.         for input statement.
  327.  
  328.     close # FNUM
  329.  
  330.         Close a file. Releases the file descriptor and flushes
  331.         out all stored data.
  332.  
  333.     def fnNAME ( VAR { , VAR } ) = EXPR
  334.  
  335.         Define a user definable function.
  336.         
  337.         Example:
  338.             10 def fnplus(x,y) = x+y
  339.             20 print fnplus(3,5) : rem prints 8
  340.  
  341.     { let } mid$( STRINGVAR, EXPR1, EXPR2 ) = STRINGEXPR
  342.  
  343.         Insert STRINGEXPR into STRINGVAR starting at EXPR1 
  344.         for character length EXPR2.
  345.  
  346.     exec(STRINGEXPR)
  347.  
  348.         Executes STRINGEXPR as a statement or command. 
  349.         e.g. exec("print " + "x") will print the value of x.
  350.  
  351.     poke ADDR_EXPR, DATA_EXPR
  352.  
  353.         Poke a byte into a memory location. Unreasonable
  354.         addresses can cause bus-errors.
  355.  
  356.     push VAR { , VAR ... }
  357.  
  358.         Pushes one or more expressions or variables onto an
  359.         internal stack.  Expressions can be returned using the
  360.         POP function; variables can be returned by using the
  361.         POP statement.
  362.     
  363.     pop VAL
  364.  
  365.         POP statement (see also POP function). Pops VAL
  366.         variables off the internal stack, restoring the value
  367.         of those variables to their pushed values.
  368.     
  369.     NUMERIC FUNCTIONS
  370.  
  371.     sgn(VAL)
  372.  
  373.         Returns the sign of the parameter value.  Returns 1 if
  374.         the value is greater than zero , zero if equal to zero.
  375.         -1 if negative.
  376.  
  377.     abs(x)
  378.  
  379.         Returns the absolute value of x.
  380.  
  381.     int(x)
  382.  
  383.         Returns the integer value of x.  Truncates toward zero.
  384.  
  385.     sqr(x)
  386.  
  387.         Returns the square root of x.
  388.  
  389.     log(x)
  390.  
  391.         Returns the natural logarithm of x.
  392.  
  393.     exp(x)
  394.  
  395.         Returns e^x. e=2.7182818...
  396.  
  397.     sin(x)
  398.     cos(x)
  399.     atn(x)
  400.  
  401.         Trigonometric functions: sin, cosine and arctangent. 
  402.  
  403.     pi
  404.     
  405.         Returns pi, 3.14159265358979323... 
  406.  
  407.     rnd(x)
  408.  
  409.         Returns a random number between 1 and int(x)-1.  If x
  410.         is negative then x seeds the random number generator.
  411.         If x is 1, then returns a fraction between 0 and 1.
  412.  
  413.     len(STRINGEXPR)
  414.  
  415.         Returns the length of the string STRINGEXPR.
  416.  
  417.     val(STRINGEXPR)
  418.  
  419.         Value of the expression contained in STRINGEXPR.
  420.         STRINGEXPR may be a string literal, variable, function,
  421.         or expression.
  422.         
  423.         For example, VAL("1+sqr(4)") yields 3.
  424.  
  425.     asc(STRINGEXPR)
  426.  
  427.         Returns the ascii code for the first character of
  428.         STRINGEXPR.  A null string returns zero.
  429.  
  430.     instr(a$, b$)
  431.  
  432.         Returns the starting position of the substring
  433.         b$ in the string a$ or zero if not found.
  434.  
  435.     eof(FILENUM)
  436.  
  437.         Returns true if the file specified by FILENUM has reached
  438.         the end of the file.
  439.  
  440.     pop
  441.  
  442.         POP function (see also POP statement). Pops one variable
  443.         value off the stack and returns that value (string or
  444.         numeric).  Useful for passing parameters.
  445.         
  446.         (POP can be used as either a statement (with a
  447.         parameter) or a function (no parameter). Note that the
  448.         POP function, unlike the POP statement, does not
  449.         restore the value of the variable pushed, but only
  450.         returns the pushed value.  This use of the POP
  451.         statement is different from the Applesoft usage.)
  452.  
  453.     peek( x { , VAL } )
  454.  
  455.         Returns the value of the byte in memory at address x.
  456.         If VAL is 2 or 4, returns the value of the 16-bit or
  457.         32-bit word respectively (but only if correctly aligned).
  458.  
  459.     varptr( VAR | STRINGVAR )
  460.     
  461.         Returns the memory address of a variable.
  462.     
  463.     erl
  464.  
  465.         Returns the line number of the last error.  Zero if the
  466.         error was in immediate mode.  The variable errorstatus$
  467.         gives the error type.
  468.  
  469.     timer
  470.  
  471.         Returns a numeric value of elapsed of seconds from the
  472.         computers internal clock.
  473.  
  474.     
  475.     STRING FUNCTIONS
  476.  
  477.     x$ + y$
  478.  
  479.         String concatenation.  Result must be 254 characters or less.
  480.     
  481.     chr$(VAL)
  482.  
  483.         Returns the ascii character corresponding to the value
  484.         of VAL.
  485.  
  486.     str$( VAL { , EXPR } )
  487.  
  488.         Returns a string representation corresponding to VAL.
  489.         If EXPR is present then the string is padded to that
  490.         length.
  491.  
  492.     inkey$
  493.  
  494.         Return one character from the keyboard if input is
  495.         available. Returns a zero length string { "" } if no
  496.         keyboard input is available.  Non-blocking.  Can be used
  497.         for keyboard polling.
  498.  
  499.     input$( EXPR { , FILENUM } )
  500.  
  501.         Returns EXPR characters from file FILENUM. If f is not present
  502.         then get input from the console keyboard.
  503.  
  504.     mid$( a$, i { , j } )
  505.  
  506.         Returns a substring of a$ starting at the i'th
  507.         positions and j characters in length. If the second
  508.         parameter is not specified then the substring is taken
  509.         from the start position to the end of a$.
  510.  
  511.     right$(a$, EXPR )
  512.  
  513.         Returns the right EXPR characters of a$.
  514.  
  515.     left$(a$, EXPR )
  516.  
  517.         Returns the left EXPR characters of a$.
  518.  
  519.     field$( STRINGVAL, VAL { , STRINGVAL } )
  520.  
  521.         Returns the n-th field of the first string.  If the
  522.         optional string is present then use the first character
  523.         of that string as the field separator.  The default
  524.         separator is a space.  Similar to UNIX 'awk' fields.
  525.         
  526.         e.g.  field$("11 22 33 44", 3)  returns  "33"
  527.  
  528.     hex$( VAL { , EXPR } )
  529.     bin$( VAL { , EXPR } )
  530.  
  531.         Returns the hexadecimal or binary string representation
  532.         corresponding to VAL.  If EXPR is present then the
  533.         string is padded with zeros to make it that length.
  534.  
  535.     lcase$( STRINGVAL )
  536.  
  537.         Returns STRINGVAL in all lower case characters.
  538.  
  539.     errorstatus$
  540.  
  541.         Returns the error message for the last error.
  542.  
  543.  
  544.     OPERATORS
  545.  
  546.     The following mathematical operators  are available:
  547.  
  548.         ^    exponentiation
  549.         *    multiplication
  550.         /    division
  551.         mod    remainder
  552.         +    addition
  553.         -    subtraction
  554.  
  555.     logical operators: (any non-zero value is true)
  556.  
  557.             not    logical not
  558.  
  559.     bitwise operators:
  560.  
  561.             and    bitwise and
  562.             or    bitwise or
  563.             xor    bitwise exclusive-or
  564.  
  565.     comparison operators:
  566.  
  567.             <=    less than or equal
  568.             <>    not equal to
  569.             >=    greater than or equal
  570.             =    equal
  571.             >    greater than
  572.             <    less than
  573.  
  574.     x$=y$, x$<y$, x$>y$, x$<=y$, x$>=y$, x$<>y$
  575.  
  576.         String comparisons; result is 1 if true, 0 if false.
  577.         
  578.     Operator precedence (highest to lowest):
  579.  
  580.         ( )
  581.         not -{unary_minus} functions
  582.         ^
  583.         * / mod
  584.         + -
  585.         = < > <= >= <>
  586.         and
  587.         or xor
  588.  
  589.     
  590.     UNIX commands and functions:
  591.  
  592.     sys( STRINGVAL )
  593.  
  594.         UNIX system call.  The string parameter is given to
  595.         the shell as a command.
  596.  
  597.     argv$
  598.         Returns the UNIX shell command line arguments.
  599.  
  600.  
  601.     Macintosh commands:
  602.  
  603.     gotoxy VAL, VAL
  604.  
  605.         Set the horizontal and vertical location of the
  606.         text output cursor.  (0,0) is the upper left corner.
  607.  
  608.     moveto VAL, VAL
  609.  
  610.         Sets the (x,y) location of the graphics pen.
  611.  
  612.     lineto VAL, VAL
  613.  
  614.         Draws a line from the current pen location to location
  615.         (x,y) in the graphics window.
  616.  
  617.     window x, y, char_cols, char_lines
  618.  
  619.         Change the text console window position and size.
  620.  
  621.     graphics window x, y, char_cols, char_lines
  622.  
  623.         Change the graphics window position and size.
  624.  
  625.     morse STRINGVAL { , VAL, VAL, VAL, VAL }
  626.  
  627.         Plays morse code through the speaker.
  628.         The parameters are { dot-speed-wpm, volume{0..100},
  629.         word-speed-wpm, frequency_cps }
  630.  
  631.     sound VAL, VAL, VAL 
  632.  
  633.         The parameters are
  634.         { frequency_cps, seconds_duration, volume{0..100} }
  635.     
  636.     say STRINGVAL
  637.  
  638.         Speaks STRINGVAL if the Speech Manager Extension is
  639.         resident.  Try "say a$,200,46,1" for faster speech.
  640.  
  641.     open "SFGetFile" for input  as #FNUM
  642.     open "SFPutFile" for output as #FNUM
  643.  
  644.         Puts up a standard file dialog for the file name.
  645.  
  646.     call EXPR
  647.     
  648.         Calls the 68K code at address EXPR. 
  649.     
  650.     Lots of other undocumented quickdraw and sprite commands.
  651.  
  652.     
  653.     Macintosh functions:
  654.     
  655.     fre
  656.         Returns the amount of memory left for program use. 
  657.     
  658.     date$
  659.         Returns a string corresponding to the current date.
  660.  
  661.     time$
  662.         Returns a string corresponding to the current time.
  663.  
  664.     pos(VAL)
  665.  
  666.         Returns the horizontal position of the text cursor.
  667.         If VAL is negative returns the vertical position.
  668.     
  669.     errorstatus$ also returns the full path name of the program and
  670.         files opened by SFGetFile, under System 7 only, if it fits.
  671.     
  672.     
  673.     Macintosh menu items:
  674.  
  675.     Open or <cmd>O     will put up a dialog to allow selection
  676.             of a program file to load.  Basic Program file
  677.             names must end with a ".bas" suffix.
  678.  
  679.     Copy        will allow copying picts from the graphics
  680.             window.
  681.     
  682.     <cmd>.         command-period will stop program execution.
  683.  
  684.     Print        Only the graphics window can be printed.
  685.  
  686.  
  687.     CONVENTIONS
  688.  
  689.     EXPR        any expression that evaluates to a numeric value.
  690.     STRINGEXPR    a string expression.
  691.     VAR        a numeric variable.
  692.     STRINGVAR    a string variable.
  693.     
  694.     All program lines must begin with a line number.  A line number
  695.     entered by itself will delete that program line. Using spaces
  696.     (indentation) between the line number and program statements is
  697.     legal.  Line numbers can be between 1 and 2147483647.
  698.     
  699.     Hexadecimal numbers can be entered by preceding them with
  700.     a "0x" as in 0x02ae, or by "&h" as in &h0172.
  701.     
  702.     Multiple statements may be given on one line, separated by
  703.     colons:
  704.  
  705.         10 INPUT X : PRINT X : STOP
  706.  
  707.  
  708.     DIAGNOSTICS
  709.  
  710.     Some errors can be caught by the user program using the "on error
  711.     goto" command. If no error trapping routine has been supplied
  712.     then program execution is terminated and a message is printed
  713.     with the corresponding line number.
  714.  
  715.     Graphics may require that the preferred memory requirements be
  716.     increased.
  717.  
  718.  
  719.     AUTHORS
  720.     
  721.     David Gillespie wrote basic.p 1.0 and the p2c lib.
  722.     Ron Nicholson (rhn@netcom.com) added file i/o and
  723.     did the Macintosh and PowerMac port.  (1990, 94-Aug)
  724.  
  725.     
  726.     BUGS
  727.  
  728.     Many.
  729.  
  730.     Macintosh screen editing will only recognise the last line modified
  731.     before a RETURN or ENTER key.
  732.  
  733.     There are several undocumented graphics and sprite commands
  734.     and keywords.
  735.  
  736.  
  737.     Portions Copyright (C) 1989 Dave Gillespie
  738.     Copyright (C) 1994 Ronald H. Nicholson, Jr., All rights reserved.
  739.     "Applesoft" is probably a trademark of Apple Computer, Inc.
  740.  
  741.